//
//  DengLuViewController.m
//  TableViewGroup
//
//  Created by 侯振兴 on 15/1/6.
//  Copyright (c) 2015年 侯振兴. All rights reserved.
//

#import "DengLuViewController.h"
#import <ShareSDK/ShareSDK.h>
#import "HomePageViewController.h"
#import "MSMenuView.h"
#import "ReadingRoomViewController.h"
#import "SettingsViewController.h"

@interface DengLuViewController ()

@end

@implementation DengLuViewController

- (void)dealloc
{
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self createDeng];
}


- (void)createDeng
{
//    UIView *bigView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 128)];
//    bigView.userInteractionEnabled = YES;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    imageView.image = [UIImage imageNamed:@"haiyang1"];
    [self.view addSubview:imageView];
    
    UIButton *xinLangButton = [[UIButton alloc] initWithFrame:CGRectMake(35, self.view.frame.size.height - 260, 64, 64)];
    [xinLangButton addTarget:self action:@selector(xinLangAction:) forControlEvents:UIControlEventTouchUpInside];
    [xinLangButton setBackgroundImage:[UIImage imageNamed:@"weibo icon.png"] forState:UIControlStateNormal];
    
    UIButton *qqButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 4 + 65, self.view.frame.size.height - 260, 64, 64)];
    [qqButton addTarget:self action:@selector(qqAction:) forControlEvents:UIControlEventTouchUpInside];
    [qqButton setBackgroundImage:[UIImage imageNamed:@"qq icon.png"] forState:UIControlStateNormal];
    
    UIButton *youxiangButton = [[UIButton alloc] initWithFrame:CGRectMake(2 * self.view.frame.size.width / 4 + 95, self.view.frame.size.height - 260, 64, 64)];
    [youxiangButton addTarget:self action:@selector(youxiangAction:) forControlEvents:UIControlEventTouchUpInside];
    [youxiangButton setBackgroundImage:[UIImage imageNamed:@"email icon.png"] forState:UIControlStateNormal];
    
    UIButton *youkeButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 50, self.view.frame.size.height - 180, 100, 30)];
    [youkeButton setTitle:@"游客身份" forState:UIControlStateNormal];
    [youkeButton addTarget:self action:@selector(youkeAction:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:youkeButton];
    [self.view addSubview:xinLangButton];
    [self.view addSubview:qqButton];
    [self.view addSubview:youxiangButton];
//    [self.view addSubview:bigView];
    [youxiangButton release];
    [qqButton release];
    [xinLangButton release];
    [youkeButton release];
//    [bigView release];
}
     
     
- (void)xinLangAction:(id)sender
{
    [ShareSDK getUserInfoWithType:ShareTypeSinaWeibo authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
        //        NSLog(@"%d",result);
        if (result) {
//            NSLog(@"授权登陆成功，已获取用户信息");
                        NSString *uid = [userInfo uid];
                        NSString *nickname = [userInfo nickname];
                        NSString *profileImage = [userInfo profileImage];
                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"登陆成功" message:[NSString stringWithFormat:@"授权登陆成功,用户ID:%@,昵称:%@,头像:%@",uid,nickname,profileImage] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                        [alert show];
//                        UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"登陆成功" message:@"您已成功登陆!" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
//                        [alert show];
            
                        SettingsViewController *homePageController = [[[SettingsViewController alloc] init] autorelease];
                        [self.navigationController pushViewController:homePageController animated:YES];
            
//            ReadingRoomViewController *readingRoom = (ReadingRoomViewController *)[[UIApplication sharedApplication].delegate window].rootViewController;
//            
////            readingRoom
//            [self dismissViewControllerAnimated:YES completion:nil];
//            [alert release];
            
                        [alert release];
            
            
            
            //存入登陆状态
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            [user setObject:@"yes" forKey:@"login"];
            
            
            //            self.judge = YES;
            //            Singleton *share = [Singleton shareInstance];
            //            share.logined = YES;
            //
            //            share.loginDefault = [NSUserDefaults standardUserDefaults];
            //            [share.loginDefault setObject:@"yes" forKey:@"登陆状态"];
                    }else{
            //            NSLog(@"分享失败,错误码:%ld,错误描述%@",(long)[error errorCode],[error errorDescription]);
            //            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Code4App" message:@"授权失败，请看日记错误描述" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            //            [alert show];
            //            [alert release];
        }
    }];
         
}

- (void)qqAction:(id)sender
{
    
}

- (void)youxiangAction:(id)sender
{
    
}

- (void)youkeAction:(id)sender
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
